package leetcode.editor.cn.q1_300.q50;

import java.util.Arrays;

/**
 * @author qidi
 * @date 2021-12-20 15:01:15
 */
class Q0080_RemoveDuplicatesFromSortedArrayIi {

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int removeDuplicates(int[] nums) {
            int n = nums.length;
            if (n <= 2) {
                return n;
            }
            int slow = 2, fast = 2;
            while (fast < n) {
                if (nums[slow - 2] != nums[fast]) {
                    nums[slow] = nums[fast];
                    ++slow;
                }
                ++fast;
            }
            return slow;
        }
    }
    //leetcode submit region end(Prohibit modification and deletion)


    public static void main(String[] args) {
        Solution solution = new Q0080_RemoveDuplicatesFromSortedArrayIi().new Solution();
        int[] arr;
        arr = new int[]{1, 1, 1, 2, 2, 3};
        System.out.println(solution.removeDuplicates(arr));
        System.out.println(Arrays.toString(arr));

        arr = new int[]{0, 0, 1, 1, 1, 1, 2, 3, 3};
        System.out.println(solution.removeDuplicates(arr));
        System.out.println(Arrays.toString(arr));
    }
}